<template>
  <div>
    <Form :disabled="disabledInfo" :model="formItem" :label-width="110" :rules="ruleValidate" ref="addForm">
      <div class="title-style">人员类型</div>
      <Row :gutter="24">
        <Col span="24">
        <FormItem label="人员类型：" prop="type">
          <RadioGroup v-model="formItem.type" @on-change="changePersonType()">
            <Radio :disabled="formItem.state === '11' || level === '45' || this.$route.query.id !== ''" style="width:30px;display:inline" :label="'1'">社区工作者</Radio>
            <Radio :disabled="formItem.state === '11' || level === '40' || this.$route.query.id !== ''" style="width:30px;display:inline" :label="'2'">村工作者</Radio>
            <Radio :disabled="formItem.state === '11' || this.$route.query.id !== ''" style="width:30px;display:inline" :label="'3'">其他工作者</Radio>
            <Radio :disabled="formItem.state === '11' || this.$route.query.id !== ''" style="width:30px;display:inline" :label="'4'">非工作者</Radio>
<!--            <Radio :disabled="formItem.state === '11'" v-for="(personItem, index) in personTypeList" v-bind:key="index" :label="personItem.number" style="width:30px;display:inline">{{personItem.type_name}}</Radio>-->
          </RadioGroup>
        </FormItem>
        </Col>


        <Col span="24">
        <FormItem label="人员分类："
                  prop="type">
          <Col span="8">
          <Select v-model="formItem.person_classification">
            <Option value="社区党组织成员">社区党组织成员</Option>
            <Option value="群众性自治组织成员">群众性自治组织成员</Option>
            <Option value="社区干事">社区干事</Option>
            <Option value="楼门院长">楼门院长</Option>
            <Option value="社区骨干">社区骨干</Option>
          </Select>
          </Col>
        </FormItem>
        </Col>



      </Row>
      <div class="title-style">基本信息</div>
      <Row :gutter="24">
        <Col span="8">
          <FormItem label="姓名：" prop="name">
            <Input v-model="formItem.name"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="证件号码：" prop="card_no">
            <Input @on-change="changeCard(formItem.card_no)" :disabled="this.$route.query.id !== '' && !this.$route.query.card_no" v-model="formItem.card_no"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="联系方式：" prop="phone">
            <Input v-model="formItem.phone" placeholder=""></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="性别：" prop="sex">
            <Select disabled v-model="formItem.sex">
              <Option disabled value="男">男</Option>
              <Option disabled value="女">女</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="婚姻状况：" prop="hunyin">
            <Select v-model="formItem.hunyin" filterable >
              <Option v-for="item in labelList.hunyin" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="民族：" prop="minzu">
            <Select v-model="formItem.minzu" filterable >
              <Option v-for="item in labelList.minzu" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="政治面貌：" prop="zzmm">
            <Select v-model="formItem.zzmm" filterable >
              <Option v-for="item in labelList.zzmm" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="是否退役士兵：" prop="tysb">
            <Select v-model="formItem.tysb" @on-change="changeTysb()">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-if="formItem.tysb == '是'">
          <FormItem label="退役士兵定向：" prop="tysbdx">
            <Select v-model="formItem.tysbdx">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="是否军嫂：" prop="js" @on-change="changeJs()">
            <Select v-model="formItem.js">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.js == '是'">
          <FormItem label="军嫂定向：" prop="zsdx">
            <Select v-model="formItem.zsdx">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" >
          <FormItem label="社工状态：" prop="work_condition">
            <Input v-model="formItem.work_condition"></Input>
          </FormItem>
        </Col>
        <Col span="8" >
          <FormItem label="出生日期" prop="zsdx">
              <Input v-model="formItem.birthday_date"></Input>
          </FormItem>
        </Col>
        <Col span="8" >
          <FormItem label="人员编号" prop="id">
              <Input v-model="formItem.id"></Input>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="是否低保或低保边缘或低保定向：" prop="dbhzn">
            <Select v-model="formItem.dbhzn">
              <Option value="1">是</Option>
              <Option value="0">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="户籍地址：" prop="hj_address">
            <Input v-model="formItem.hj_address"></Input>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="家庭住址：" prop="jt_address">
            <Input v-model="formItem.jt_address"></Input>
          </FormItem>
        </Col>
      </Row>
      <Row :gutter="24">
        <Col span="8">
          <FormItem label="免冠照片" prop="mgzp">
            <img :src="nophoto" v-show="formItem.mgzp == ''" alt="" style="width:80px;height:80px;margin-left:20px;margin-bottom:5px;">
            <img :src="formItem.mgzp" v-show="formItem.mgzp != ''" alt="" style="width:80px;height:80px;margin-left:20px;margin-bottom:5px;">
            <Upload multiple action="http://120.27.63.37:38081/api/ac/file/fileCommonService/upLoadFiles"
                :before-upload="beforeUpload">
              <Button icon="ios-cloud-upload-outline" @click="uploadImg('mg')">上传免冠照片</Button>
            </Upload>
            </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="身份证正面照片" prop="sfzzm">
            <img :src="nophoto" v-show="formItem.sfzzm == ''" alt="" style="width:80px;height:80px;margin-left:20px;margin-bottom:5px;">
            <img :src="formItem.sfzzm" v-show="formItem.sfzzm != ''" alt="" style="width:80px;height:80px;margin-left:35px;margin-bottom:5px;">
            <Upload multiple action="http://120.27.63.37:38081/api/ac/file/fileCommonService/upLoadFiles"
                :before-upload="beforeUpload">
              <Button icon="ios-cloud-upload-outline" @click="uploadImg('zm')">上传身份证正面照片</Button>
            </Upload>
            </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="身份证反面照片" prop="sfzfm">
            <img :src="nophoto" v-show="formItem.sfzfm == ''" alt="" style="width:80px;height:80px;margin-left:20px;margin-bottom:5px;">
            <img :src="formItem.sfzfm" v-show="formItem.sfzfm != ''" alt="" style="width:80px;height:80px;margin-left:35px;margin-bottom:5px;">
            <Upload multiple action="http://120.27.63.37:38081/api/ac/file/fileCommonService/upLoadFiles"
                :before-upload="beforeUpload">
              <Button icon="ios-cloud-upload-outline" @click="uploadImg('fm')">上传身份证反面照片</Button>
            </Upload>
            </FormItem>
        </Col>
      </Row>
      <div class="title-style">教育信息</div>
      <Row :gutter="24">
        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2'">
          <FormItem label="毕业院校：" prop="byyx">
            <Input v-model="formItem.byyx"></Input>
            <!-- <DatePicker type="date" v-model="formItem.byyx" placeholder="" style="width: 200px"></DatePicker> -->
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2'">
          <FormItem label="所学专业：" prop="sxzy">
            <Input v-model="formItem.sxzy"></Input>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2'">
          <FormItem label="最高学历：" prop="zgxl">
            <Select v-model="formItem.zgxl" filterable>
              <Option v-for="item in labelList.zgxl" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2'">
          <FormItem label="学位：" prop="xw">
            <Select v-model="formItem.xw" filterable>
              <Option v-for="item in labelList.xw" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2'">
          <FormItem label="毕业时间：" prop="bysj">
            <DatePicker type="date" v-model="formItem.bysj" placeholder="" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
      </Row>
      <div class="title-style">职业信息</div>
      <Row :gutter="24">
<!--        <Col span="8" v-show="formItem.type == '1'">-->
<!--          <FormItem label="社会工作师职业资格：" prop="shgzs">-->
<!--            <Select v-model="formItem.shgzs" filterable>-->
<!--              <Option v-for="item in labelList.shgzs" :key="item.number" :value="item.number">{{item.type_name}}</Option>-->
<!--            </Select>-->
<!--          </FormItem>-->
<!--        </Col>-->
<!--        <Col span="8" v-show="formItem.type == '1'">-->
<!--          <FormItem label="社会工作师职业资格取得时间：">-->
<!--            <DatePicker type="date" v-model="formItem.shgzssj" placeholder="" style="width: 200px"></DatePicker>-->
<!--          </FormItem>-->
<!--        </Col>-->
<!--        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2' || formItem.type == '3'">-->
<!--          <FormItem prop="area1">-->
<!--            <template slot="label">-->
<!--              <span class="red-star">*</span><span>所属市区：</span>-->
<!--              <Icon type="md-help-circle" class="help-tip" @click="showHelp(1)"/>-->
<!--            </template>-->
<!--            <Select v-model="formItem.area1" placeholder="" filterable @on-change="getMailList(4, formItem.area1)">-->
<!--              <Option v-for="obj in inoutCity.areaList" :value="obj.code" :key="obj.code">{{obj.name}}</Option>-->
<!--            </Select>-->
<!--          </FormItem>-->
<!--        </Col>-->
<!--        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2' || formItem.type == '3'">-->
<!--          <FormItem prop="area2">-->
<!--            <template slot="label">-->
<!--              <span class="red-star">*</span><span>街道：</span>-->
<!--              <Icon type="md-help-circle" class="help-tip" @click="showHelp(1)"/>-->
<!--            </template>-->
<!--            <Select v-model="formItem.area2" placeholder="" filterable @on-change="chaneProv(5, formItem.area2)">-->
<!--              <Option v-for="obj in inoutCity.areaList1" :value="obj.code" :key="obj.code">{{obj.name}}</Option>-->
<!--            </Select>-->
<!--          </FormItem>-->
<!--        </Col>-->
<!--        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2' || formItem.type == '3'">-->
<!--          <FormItem prop="area3">-->
<!--            <template slot="label">-->
<!--              <span class="red-star">*</span><span>社区：</span>-->
<!--              <Icon type="md-help-circle" class="help-tip" @click="showHelp(1)"/>-->
<!--            </template>-->
<!--            <Select v-model="formItem.area3" placeholder="" filterable @on-change="chaneProv()">-->
<!--              <Option v-for="obj in inoutCity.areaList2" :value="obj.code" :key="obj.code">{{obj.name}}</Option>-->
<!--            </Select>-->
<!--          </FormItem>-->
<!--        </Col>-->
        <Col span="8">
          <FormItem label="党委职务：" prop="dwzw">
            <Select v-model="formItem.dwzw" filterable >
              <Option v-for="item in labelList.dwzw" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="居委职务：" prop="jwzw">
            <Select v-model="formItem.jwzw" filterable >
              <Option v-for="item in labelList.jvwzw" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="监委职务：" prop="jwcy">
            <Select v-model="formItem.jwcy" filterable >
              <Option v-for="item in labelList.jwzw" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="协会职务：" prop="xhzw">
            <Select v-model="formItem.xhzw" filterable >
              <Option v-for="item in labelList.xhzw" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>


        <Col span="8"
             v-show="formItem.type == '1'">
        <FormItem label="所属区县："
                  prop="be_country">
                  <Input 
                 v-model="formItem.be_country"></Input>
        </FormItem>
        </Col>
        <Col span="8"
             v-show="formItem.type == '1'">
        <FormItem  prop="work_condition" label="任职情况：">
          <Select v-model="formItem.work_condition"
                 >
            <Option value="在职">在职</Option>
            <Option value="停职">停职</Option>
            <Option value="离职">离职</Option>
          </Select>
        </FormItem>
        </Col>




        <Col span="8" v-show="formItem.type == '1' || formItem.type == '2'">
          <FormItem label="入职时间：" prop="rzsj">
            <DatePicker type="date" v-model="formItem.rzsj" placeholder="" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8"  v-show="formItem.type == '1' || formItem.type == '2'">
          <FormItem label="任职时间：" prop="rz_time">
            <DatePicker type="date" v-model="formItem.rz_time" placeholder="" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="笔试成绩：" prop="bscj">
            <Input type="number" v-model="formItem.bscj"></Input>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="面试成绩：" prop="mscj">
            <Input type="number" v-model="formItem.mscj"></Input>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="是否取得全科社工资格：" prop="qksgzg">
            <Select v-model="formItem.qksgzg">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8"  v-show="formItem.type == '1' && formItem.qksgzg === '是'">
          <FormItem label="全科社工资格取得时间：" prop="qksg_time">
            <DatePicker type="date" v-model="formItem.qksg_time" placeholder="" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="社会工作师职业资格：" prop="shgzs">
            <Select v-model="formItem.shgzs" filterable>
              <Option v-for="item in labelList.shgzs" :key="item.number" :value="item.number">{{item.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="社会工作师职业资格取得时间：">
            <DatePicker type="date" v-model="formItem.shgzssj" placeholder="" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="是否返聘：">
            <Select v-model="formItem.fp" @on-change="changeFp()">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8"  v-show="formItem.type == '1' && formItem.fp === '是'">
          <FormItem label="返聘原因：">
            <Input v-model="formItem.fpyy"></Input>
          </FormItem>
        </Col>
      </Row>
      <div v-if="formItem.type === '1'" class="title-style">其他信息</div>
      <Row :gutter="24">
        <Col  span="8" v-show="formItem.type == '1'">
          <FormItem label="培训记录：">
            <Select v-model="formItem.pxjl">
              <Option value="10">全员培训</Option>
              <Option value="20">社区工作者专门培训</Option>
            </Select>
          </FormItem>
        </Col>
        <Col  span="8" v-show="formItem.type == '1'">
          <FormItem label="综合评定：">
            <Select v-model="formItem.pxpd">
              <Option v-for="obj in labelList.khjg" :value="obj.type_name" :key="obj.number">{{obj.type_name}}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col  span="8" v-show="formItem.type == '1'">
          <FormItem label="是否签订劳动合同：">
            <Select v-model="formItem.ldht">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="劳动合同甲方：">
            <Input v-model="formItem.ldhtjf"></Input>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="其他甲方：">
            <Input v-model="formItem.qtjf"></Input>
          </FormItem>
        </Col>
        <Col span="8"  v-show="formItem.type == '1'">
          <FormItem label="劳动关系证明">
            <Input v-model="formItem.ldgxzm"></Input>
          </FormItem>
        </Col>
        <Col span="8"  v-show="formItem.type == '1'">
          <FormItem label="其他证明">
            <Input v-model="formItem.qtzm"></Input>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="初次缴纳时间：">
            <DatePicker type="date" v-model="formItem.cjjn_time" placeholder="" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="是否财政负担保险：">
            <Select v-model="formItem.czfdbx">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8"  v-show="formItem.type == '1'">
          <FormItem label="其他财政负担保险：">
            <Input v-model="formItem.qtczfdbx"></Input>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="是否连续缴纳：">
            <Select v-model="formItem.lxjn">
              <Option value="是">是</Option>
              <Option value="否">否</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8" v-show="formItem.type == '1'">
          <FormItem label="连续缴纳时间：">
            <DatePicker type="date" v-model="formItem.lxjn_time" placeholder="" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
      </Row>
      <div v-if="formItem.type === '1'" class="title-style">亲属信息</div>
      <Table :columns="familyColumns" :data="familyList" border  v-if="formItem.type === '1'">
        <template slot-scope="{ row }" slot="zzmm">
          <div v-for="item in labelList.zzmm" :key="item.number">
            <span v-if="item.number === row.zzmm">{{ item.type_name }}</span>
          </div>
        </template>
        <template slot-scope="{ row }" slot="gx">
          <div v-for="item in labelList.qsgx" :key="item.number">
            <span v-if="item.number === row.gx">{{ item.type_name }}</span>
          </div>
        </template>
        <template slot-scope="{ row }" slot="operate">
          <Button type="primary" @click="updateFamily(row)" style="margin-right: 10px">编辑</Button>
          <Button type="error" @click="deleteFamily(row)">删除</Button>
        </template>
      </Table>
      <Button  v-if="formItem.type === '1'" style="margin-top: 10px; width: 90%; margin-left: 5%" type="dashed" @click="addFamily">添加亲属信息</Button>
      <div v-if="formItem.type === '1'" class="title-style">考核信息</div>
      <Table :columns="assessmentColumns" :data="assessmentList" border v-if="formItem.type === '1'">
        <template slot-scope="{ row }" slot="khlx">
          <div v-for="item in labelList.khxx" :key="item.number">
            <span v-if="item.number === row.khlx">{{ item.type_name }}</span>
          </div>
        </template>
        <template slot-scope="{ row }" slot="khcj">
          <div v-for="item in labelList.khjg" :key="item.number">
            <span v-if="item.number === row.khcj">{{ item.type_name }}</span>
          </div>
        </template>
        <template slot-scope="{ row }" slot="operate">
          <Button type="primary" @click="updateAssessment(row)" style="margin-right: 10px">编辑</Button>
          <Button type="error" @click="deleteAssessment(row)">删除</Button>
        </template>
      </Table>
      <Button v-if="formItem.type === '1'" style="margin-top: 10px; width: 90%; margin-left: 5%" type="dashed" @click="addAssessment()">添加考核信息</Button>
      <FormItem>
        <div style="margin-top: 10px;text-align: center;">
          <Button type="primary" v-if="formItem.state === '11' && !disabledInfo" @click="updateSubmit('formValidate')">提交</Button>
          <Button type="success" v-if="(formItem.state === '50' || formItem.state === '') && !disabledInfo" style="margin-left: 8px" @click="saveInfo()">保存</Button>
          <Button type="info" v-if="(formItem.state === '50' || formItem.state === '') && !disabledInfo" style="margin-left: 8px" @click="handleSubmit('formValidate')">提交</Button>
          <Button v-if="!disabledInfo" @click="handleReset('formValidate')" style="margin-left: 8px">返回</Button>
        </div>
      </FormItem>
    </Form>
    <div style="margin-top: 10px;text-align: center;" v-if="disabledInfo">
      <Button @click="handleReset('formValidate')" style="margin-left: 8px">返回</Button>
    </div>

    <Modal
      v-model="familyShow"
      title="亲属信息"
      @on-ok="addFamilyOk"
      @on-cancel="familyShow = false">
      <Form :model="familyData" :label-width="80">
        <FormItem label="姓名">
          <Input v-model="familyData.name"></Input>
        </FormItem>
        <FormItem label="联系方式">
          <Input v-model="familyData.mobile"></Input>
        </FormItem>
        <FormItem label="政治面貌">
          <Select v-model="familyData.zzmm">
            <Option v-for="item in labelList.zzmm" :key="item.number" :value="item.number">{{ item.type_name }}</Option>
          </Select>
        </FormItem>
        <FormItem label="亲属关系">
          <Select v-model="familyData.gx">
            <Option v-for="item in labelList.qsgx" :key="item.number" :value="item.number">{{ item.type_name }}</Option>
          </Select>
        </FormItem>
        <FormItem label="工作单位">
          <Input v-model="familyData.gzdw"></Input>
        </FormItem>
      </Form>
    </Modal>

    <Modal
      v-model="assessmentShow"
      title="考核信息"
      @on-ok="addAssessmentOk"
      @on-cancel="familyShow = false">
      <Form :model="assessmentData" :label-width="80">
        <FormItem label="考核类型">
          <Select v-model="assessmentData.khlx">
            <Option v-for="item in labelList.khxx" :key="item.number" :value="item.number">{{ item.type_name }}</Option>
          </Select>
        </FormItem>
        <FormItem label="考核成绩">
          <Select v-model="assessmentData.khcj">
            <Option v-for="item in labelList.khjg" :key="item.number" :value="item.number">{{ item.type_name }}</Option>
          </Select>
        </FormItem>
        <FormItem label="考核时间">
          <DatePicker type="date" v-model="assessmentData.kh_time" placeholder="" style="width: 100%"></DatePicker>
        </FormItem>
      </Form>
    </Modal>

  </div>
</template>
<script>
import validateData from './validate'
import * as imageConversion from 'image-conversion'
import { date2str } from '@/api/eventlist'
import { getSign, createUpLoadFiles } from '@/api/common'
import { getTypeList, getOffice } from '@/api/personInfo'
import nophoto from '@/assets/images/nophoto.jpeg'
import { saveCommunityPeople, getPersonnelInfo, updatePersonnelInfo, saveInfo } from '@/api/worker.js'
import {getUuid} from "../../../api/eventlist";
export default {
  data () {
    return {
      personnelType: '',
      deleteFamilyList: [],
      deleteAssessmentList: [],
      disabledInfo: false,
      ruleValidate: validateData.ruleValidate1,
      personnel_type: '',
      familyData: {},
      familyShow: false,
      assessmentData: {},
      assessmentShow: false,
      formItem: {
        type: '1',
        mgzp: '',
        sfzzm: '',
        sfzfm: '',
        area1: '',
        state: '',
        birthday_date:'',
      },
      upPicData: {
        fileName: '',
        filePath: 'smz/cardm',
        file: ''
      },
      imgType: '',
      nophoto,
      personTypeList: [],
      familyList: [],
      assessmentList: [],
      familyColumns: [
        { type: 'index', width: 60, align: 'center' },
        { title: '姓名', key: 'name', align: 'center'},
        { title: '政治面貌', slot: 'zzmm', align: 'center'},
        { title: '联系电话', key: 'mobile', align: 'center'},
        { title: '亲属关系', slot: 'gx', align: 'center'},
        { title: '工作单位', key: 'gzdw', align: 'center'},
        { title: '操作', slot: 'operate', align: 'center'},
      ],
      assessmentColumns: [
        { type: 'index', width: 60, align: 'center' },
        { title: '考核类型', slot: 'khlx', align: 'center'},
        { title: '考核成绩', slot: 'khcj', align: 'center'},
        { title: '考核时间', key: 'kh_time', align: 'center'},
        { title: '操作', slot: 'operate', align: 'center'},
      ],
      labelList: { hunyin: [], minzu: [], zzmm: [], dwzw: [], jwzw: [], jvwzw: [], xhzw: [], zgxl: [], xw: [], shgzs: [], qsgx: [], khjg: [], khxx: [] },
      inoutCity: { areaList1: [], areaList2: [], areaList3: [] },
    }
  },
  methods: {
    uploadImg (type) {
      this.imgType = type
    },
    // 把图片文件作为参数传递到方法中进行压缩
    beforeAvatarUpload (file) {
      const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
      if (!isJpgOrPng) {
        this.$Notice.error({ title: '上传失败', desc: '上传头像图片只能是 JPG 或 PNG 格式!' })
        return false
      }
      return new Promise(() => {
        imageConversion.compressAccurately(file, 200).then(res => {
          let that = this
          const reader = new FileReader()
          reader.readAsDataURL(new File([res], '', { type: res.type, lastModified: Date.now() }))
          reader.onload = () => {
            let index = reader.result.indexOf('base64,') + 7
            that.upPicData.fileName = this.upPicData.fileName + '.' + file.type.substring(6)
            that.upPicData.file = reader.result.substring(index)
            that.upPic(that.upPicData)
          }
        })
      })
    },
    // 上传图片前转base64
    beforeUpload (file) {
      console.log(file, '图片文件')
      if (file.size / 1024 / 1024 > 1) { // 超过1M 压缩 图片为200K
        return this.beforeAvatarUpload(file)
      }
      const isLt2M = file.size / 1024 / 1024 < 8
      console.log(isLt2M)
      if (!isLt2M) {
        this.$Notice.error({ title: '上传失败', desc: '请上传图片小于8M的图片' })
        return
      }
      // return isLt2M
      this.upPicData.fileName = file.name
      let that = this
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = () => {
        let index = reader.result.indexOf('base64,') + 7
        that.upPicData.file = reader.result.substring(index)
        that.upPic(that.upPicData)
      }
      return false
    },
    // 上传图片
    upPic (obj) {
      var time = new Date().getTime()
      this.timeStep = time.toString()
      let param = {
        filePath: obj.filePath,
        fileName: obj.fileName,
        timestamp: this.timeStep
      }
      if (param.fileName.length > 20) {
        param.fileName = param.fileName.substring(0, 20) + '.png'
      }
      getSign(param).then(res => {
        if (res.data.errcode === 0) {
          createUpLoadFiles(res.data.data.docking_url, {
            sign: res.data.data.sign,
            timestamp: this.timeStep,
            filePath: param.filePath,
            fileName: param.fileName,
            file: obj.file
          }).then(res => {
            if (res.data.errcode === 0) {
              if (this.imgType === 'mg') {
                this.formItem.mgzp = res.data.data
              } else if (this.imgType === 'zm') {
                this.formItem.sfzzm = res.data.data
              } else if (this.imgType === 'fm') {
                this.formItem.sfzfm = res.data.data
              }
              console.log(this.formItem.mgzp, 'this.formItem.mgzp')
            } else {
              this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
            }
          })
        } else {
          this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
        }
      })
    },
    getPersonTypeInfo () { // 获取人员类型
      console.log(this.level, '-----------=================')
      let param = {
        pid: '10001'
      }
      getTypeList(param).then(res => {
        if (res.data.errcode === 0) {
          this.personTypeList = res.data.data
          console.log(res.data.data)
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
    },
    changePersonType () {
      console.log(this.formItem.type, this.level,this.personnelType,'@@@@')
      if (this.formItem.type === '1') {
        this.ruleValidate = validateData.ruleValidate1
      } else if (this.formItem.type === '2') {
        this.ruleValidate = validateData.ruleValidate2
      } else if (this.formItem.type === '3') {
        this.ruleValidate = validateData.ruleValidate3
      } else if (this.formItem.type === '4') {
        this.ruleValidate = validateData.ruleValidate4
      }
      this.personnelType = this.formItem.type
    },
    getLabelList () { // 获取字典数据
      let param1 = { // 婚姻
        pid: '10006'
      }
      let param2 = { // 民族
        pid: '10008'
      }
      let param3 = { // 政治面貌
        pid: '10009'
      }
      let param4 = { // 党委职务
        pid: '10002'
      }
      let param5 = { // 居委职务
        pid: '10003'
      }
      let param6 = { // 监委职务
        pid: '10004'
      }
      let param7 = { // 协会职务
        pid: '10005'
      }
      let param8 = { // 最高学历
        pid: '10010'
      }
      let param9 = { // 学位
        pid: '10011'
      }
      let param10 = { // 学位
        pid: '10012'
      }
      let param11 = { // 亲属关系
        pid: '10015'
      }
      let param12 = { // 考核结果
        pid: '10014'
      }
      let param13 = { // 考核信息
        pid: '10013'
      }
      getTypeList(param1).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.hunyin = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param2).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.minzu = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param3).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.zzmm = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param4).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.dwzw = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param5).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.jvwzw = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param6).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.jwzw = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param7).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.xhzw = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param8).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.zgxl = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param9).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.xw = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param10).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.shgzs = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param11).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.qsgx = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param12).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.khjg = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
      getTypeList(param13).then(res => {
        if (res.data.errcode === 0) {
          this.labelList.khxx = res.data.data
          return
        }
        this.$Notice.error({ title: '查询失败' })
      })
    },
    handleSubmit (name) {
      if (confirm('是否提交审核，审核期间无法修改信息')) {
        this.$refs.addForm.validate((valid) => {
          console.log(valid, '-----------------')
          if (valid) {
            // this.$Message.success('Success!');
            // console.log(this.formItem.mgzp, '%%%%%%')
            if (this.formItem.mgzp === '' || this.formItem.mgzp === undefined) {
              this.$Message.error('请上传免冠照片！')
              return false
            } else {
              this.handleSubmitOk()
            }
          } else {
            this.$Message.error('将信息填写完整！')
            return
          }
          // else {
          //   this.$Message.error('Fail!');
          // }
        })
      }
    },
    handleSubmitOk (name) { // 提交数据
      // if (confirm('是否提交审核，审核期间无法修改信息')) {
      //   this.$refs.addForm.validate((valid) => {
      //     console.log(valid, '-----------------')
      //     if (valid) {
      //       // this.$Message.success('Success!');
      //       // console.log(this.formItem.mgzp, '%%%%%%')
      //       if (this.formItem.mgzp === '' || this.formItem.mgzp === undefined) {
      //         this.$Message.error('请上传免冠照片！')
      //         return false
      //       }
      //     } else {
      //       this.$Message.error('将信息填写完整！')
      //       return
      //     }
          // else {
          //   this.$Message.error('Fail!');
          // }
        // })
        let params = {}
        if (this.formItem.id) {
          params.id = this.formItem.id
        }
        if (this.formItem.bysj) {
          params.bysj = date2str(this.formItem.bysj)
        }
        if (this.formItem.rzsj) {
          params.rzsj = date2str(this.formItem.rzsj)
        }
        if (this.formItem.rz_time) {
          params.rz_time = date2str(this.formItem.rz_time)
        }
        if (this.formItem.shgzssj) {
          params.shgzssj = date2str(this.formItem.shgzssj)
        }
        if (this.formItem.lxjn_time) {
          params.lxjn_time = date2str(this.formItem.lxjn_time)
        }
        if (this.formItem.qksg_time) {
          params.qksg_time = date2str(this.formItem.qksg_time)
        }
        if (this.formItem.cjjn_time) {
          params.cjjn_time = date2str(this.formItem.cjjn_time)
        }
        if (this.formItem.lxjn_time) {
          params.lxjn_time = date2str(this.formItem.lxjn_time)
        }
        params = {
          ...params,
          type: this.formItem.type,
          name: this.formItem.name,
          card_no: this.formItem.card_no,
          phone: this.formItem.phone,
          sex: this.formItem.sex,
          hunyin: this.formItem.hunyin,
          minzu: this.formItem.minzu,
          zzmm: this.formItem.zzmm,
          dwzw: this.formItem.dwzw,
          jwzw: this.formItem.jwzw,
          jwcy: this.formItem.jwcy,
          hj_address: this.formItem.hj_address,
          jt_address: this.formItem.jt_address,
          mgzp: this.formItem.mgzp,
          sfzzm: this.formItem.sfzzm,
          sfzfm: this.formItem.sfzfm,

        }
        if (this.formItem.type === '1') {
          params = {
            ...params,
            tysb: this.formItem.tysb,
            tysbdx: this.formItem.tysbdx,
            js: this.formItem.js,
            zsdx: this.formItem.zsdx,
            xhzw: this.formItem.xhzw,
            dbhzn: this.formItem.dbhzn,
            byyx: this.formItem.byyx,
            sxzy: this.formItem.sxzy,
            zgxl: this.formItem.zgxl,
            xw: this.formItem.xw,
            bscj: this.formItem.bscj,
            mscj: this.formItem.mscj,
            qksgzg: this.formItem.qksgzg,
            shgzs: this.formItem.shgzs,
            fp: this.formItem.fp,
            fpyy: this.formItem.fpyy,
            pxjl: this.formItem.pxjl,
            pxpd: this.formItem.pxpd,
            ldht: this.formItem.ldht,
            ldhtjf: this.formItem.ldhtjf,
            qtjf: this.formItem.qtjf,
            ldgxzm: this.formItem.ldgxzm,
            qtzm: this.formItem.qtzm,
            czfdbx: this.formItem.czfdbx,
            qtczfdbx: this.formItem.qtczfdbx,
            lxjn: this.formItem.lxjn,
            familyList: this.familyList,
            assessmentList: this.assessmentList,
            deleteFamilyList: this.deleteFamilyList,
            deleteAssessmentList: this.deleteAssessmentList
          }
        } else if (this.formItem.type === '2') {
          params = {
            ...params,
            byyx: this.formItem.byyx,
            sxzy: this.formItem.sxzy,
            zgxl: this.formItem.zgxl,
            xw: this.formItem.xw,
          }
        }
        this.formItem.familyList = this.familyList
        this.formItem.assessmentList = this.assessmentList
        saveCommunityPeople(params).then(res => {
          if (res.data.errcode === 0) {
            this.$Message.success('操作成功')
            this.$router.push({
              path: '/personnel-list',
              query: { labelList: this.labelList }
            })
          } else {
            this.$Message.error(res.data.errmsg);
          }
        })
      // }
    },
    // chaneProv (grade, index) { // 选择区街道社区
    //   console.log('####', this.formItem['area' + index])
    //   let temparea = this.formItem['area' + index]
    //   if (!temparea) {
    //     return
    //   }
    //   // let templist = this.inoutCity.areaList +
    //   // let tempdata = {}
    //   for (let i = 0; i < templist.length; i++) {
    //     if (temparea === templist[i].name) {
    //       tempdata = templist[i]
    //       break
    //     }
    //   }
    //   this.getCity(grade, tempdata.code, 'areaList' + index, false)
    // },
    getCity (grade, code, listname, flag) { // 获取区数据
      getOffice({ code: code, grade: grade }).then(res => {
        if (res.data.errcode === 0) {
          this.inoutCity[listname] = res.data.data
          console.log(this.inoutCity[listname])
          if (flag) {
            if (this.formInfo.area1) {
              this.chaneProv(3, 1)
            }
            if (this.formInfo.area2) {
              this.chaneProv(4, 2)
            }
          }
        } else {
          this.$Notice.error({ title: '查询失败' })
        }
      })
    },
    getMailList (grade, code) {
      console.log(code)
      getOffice({ code: code }).then(res => {
        if (res.data.errcode === 0) {
          if (grade === 4) {
            this.inoutCity.areaList1 = res.data.data
            let xiehui = {code: "1", name: "社区工作者协会", master: "社区工作者协会"}
            this.inoutCity.areaList1.push(xiehui)
          } else if (grade === 5) {
            this.inoutCity.areaList2 = res.data.data
          }
          // this.mailList[index].unshift({ id: 0, title: '全部' })
          // this.$forceUpdate()
        } else {
          this.$Notice.error({ title: '获取信息失败', desc: '查询区域列表信息失败' })
        }
      })
    },
    addFamily () {
      this.familyData = {}
      this.familyShow = true
    },
    updateFamily (item) {
      this.familyData = item
      this.familyShow = true
    },
    addFamilyOk () {
      // let uuid =
      if (this.familyData.gzdw && this.familyData.gx && this.familyData.zzmm && this.familyData.mobile && this.familyData.name) {
        let id = getUuid()
        if (this.familyData.id) {
          return
        } else {
          this.familyData.id = id
          this.familyList.push(this.familyData)
          this.familyShow = false
        }
      } else {
        this.$Notice.error({ title: '请将家庭成员信息补全' })
      }

    },
    addAssessment () {
      this.assessmentData = {}
      this.assessmentShow = true
    },
    addAssessmentOk () {
      this.assessmentData.kh_time = date2str(this.assessmentData.kh_time)
      if (this.assessmentData.kh_time && this.assessmentData.khcj && this.assessmentData.khlx) {
        let id = getUuid()
        if (this.assessmentData.id) {
          return
        } else {
          this.assessmentData.id = id
          this.assessmentList.push(this.assessmentData)
          this.assessmentShow = false
        }
      } else {
        this.$Notice.error({ title: '请将考核信息补全' })
      }

    },
    updateAssessment (item) {
      this.assessmentData = item
      this.assessmentShow = true
    },
    /*
    * 当type=1时获取出生日期,type=2时获取性别,type=3时获取年龄
    * */
    IdCard(IdCard, type) {
        if (type === 1) {
            //获取出生日期
            let birthday = IdCard.substring(6, 10) + "-" + IdCard.substring(10, 12) + "-" + IdCard.substring(12, 14)
            return birthday
        }
        if (type === 2) {
            //获取性别
            if (parseInt(IdCard.substr(16, 1)) % 2 === 1) {
                return "男"
            } else {
                return "女"
            }
        }
        if (type === 3) {
            //获取年龄
            var ageDate = new Date()
            var month = ageDate.getMonth() + 1
            var day = ageDate.getDate()
            var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1
            if (IdCard.substring(10, 12) < month || IdCard.substring(10, 12) === month && IdCard.substring(12, 14) <= day) {
                age++
            }
            if (age <= 0) {
                age = 1
            }
            return age
        }
    },
    getPersonnelInfo () {
      let param = {
        id: this.$route.query.id
      }
      getPersonnelInfo(param).then(res =>{
        if (res.data.errcode === 0) {
          let data = res.data.data
          this.formItem = this.$common.xeUtils.clone(data,true)
          // if (this.formItem.type === '1') {
          //   this.formItem.type = '2'
          // } else {
          //   this.formItem.type = '1'
          // }
          this.formItem.type = data.type
          this.formItem.birthday_date = this.IdCard(this.formItem.card_no,1)
          this.changePersonType()
          this.familyList = this.formItem.familyList
          this.assessmentList = this.formItem.assessmentList
        }
      })
    },
    updateSubmit () {
      if (confirm('是否修改此人信息并提交审核，审核期间无法进行其他操作')) {
        this.$refs.addForm.validate((valid) => {
          if (valid) {
            // this.$Message.success('Success!');
            // console.log(this.formItem.mgzp, '%%%%%%')
            if (this.formItem.mgzp === '' || this.formItem.mgzp === undefined) {
              this.$Message.error('请上传免冠照片！')
              return false
            }
          } else {
            this.$Message.error('Fail!');
          }
        })
        let params = {}
        if (this.formItem.bysj) {
          params.bysj = date2str(this.formItem.bysj)
        }
        if (this.formItem.rzsj) {
          params.rzsj = date2str(this.formItem.rzsj)
        }
        if (this.formItem.rz_time) {
          params.rz_time = date2str(this.formItem.rz_time)
        }
        if (this.formItem.shgzssj) {
          params.shgzssj = date2str(this.formItem.shgzssj)
        }
        if (this.formItem.lxjn_time) {
          params.lxjn_time = date2str(this.formItem.lxjn_time)
        }
        if (this.formItem.qksg_time) {
          params.qksg_time = date2str(this.formItem.qksg_time)
        }
        if (this.formItem.cjjn_time) {
          params.cjjn_time = date2str(this.formItem.cjjn_time)
        }
        if (this.formItem.lxjn_time) {
          params.lxjn_time = date2str(this.formItem.lxjn_time)
        }
        params = {
          ...params,
          id: this.formItem.id,
          type: this.formItem.type,
          name: this.formItem.name,
          card_no: this.formItem.card_no,
          phone: this.formItem.phone,
          sex: this.formItem.sex,
          hunyin: this.formItem.hunyin,
          minzu: this.formItem.minzu,
          zzmm: this.formItem.zzmm,
          dwzw: this.formItem.dwzw,
          jwzw: this.formItem.jwzw,
          jwcy: this.formItem.jwcy,
          hj_address: this.formItem.hj_address,
          jt_address: this.formItem.jt_address,
          mgzp: this.formItem.mgzp,
          sfzzm: this.formItem.sfzzm,
          sfzfm: this.formItem.sfzfm,

        }
        if (this.formItem.type === '1') {
          params = {
            ...params,
            tysb: this.formItem.tysb,
            tysbdx: this.formItem.tysbdx,
            js: this.formItem.js,
            zsdx: this.formItem.zsdx,
            xhzw: this.formItem.xhzw,
            dbhzn: this.formItem.dbhzn,
            byyx: this.formItem.byyx,
            sxzy: this.formItem.sxzy,
            zgxl: this.formItem.zgxl,
            xw: this.formItem.xw,
            bscj: this.formItem.bscj,
            mscj: this.formItem.mscj,
            qksgzg: this.formItem.qksgzg,
            shgzs: this.formItem.shgzs,
            fp: this.formItem.fp,
            fpyy: this.formItem.fpyy,
            pxjl: this.formItem.pxjl,
            pxpd: this.formItem.pxpd,
            ldht: this.formItem.ldht,
            ldhtjf: this.formItem.ldhtjf,
            qtjf: this.formItem.qtjf,
            ldgxzm: this.formItem.ldgxzm,
            qtzm: this.formItem.qtzm,
            czfdbx: this.formItem.czfdbx,
            qtczfdbx: this.formItem.qtczfdbx,
            lxjn: this.formItem.lxjn,
            familyList: this.familyList,
            assessmentList: this.assessmentList,
            deleteAssessmentList: this.deleteAssessmentList,
            deleteFamilyList: this.deleteFamilyList
          }
        } else if (this.formItem.type === '2') {
          params = {
            ...params,
            byyx: this.formItem.byyx,
            sxzy: this.formItem.sxzy,
            zgxl: this.formItem.zgxl,
            xw: this.formItem.xw,
          }
        }
        updatePersonnelInfo(params).then(res => {
          if (res.data.errcode === 0) {
            this.$Message.success('操作成功')
            this.$router.push({
              path: '/personnel-list',
              query: { labelList: this.labelList }
            })
          } else {
            this.$Message.error(res.data.errmsg);
          }
        })
      }
    },
    handleReset () {
      this.$router.push({
        path: '/personnel-list',
        query: { labelList: this.labelList }
      })
    },
    transfer (item) {
      this.transferInfo = item
      // this.transferIfo.
      this.transferInfo.out_city_code = item.city_code
      this.transferInfo.out_street_code = item.street_code
      this.transferInfo.out_community_code = item.community_code
      this.getMailList(2,null)
      this.getMailList3(2,null)
      this.getMailList4(4,item.city_code)
      this.getMailList4(5,item.street_code)
      this.transferInfo.put_city_code = null
      this.transferInfo.put_street_code = null
      this.transferInfo.put_community_code = null
      this.transferModal = true
    },
    deleteAssessment (item) {
      for (let i = 0; i < this.assessmentList.length; i++) {
        if (item.id === this.assessmentList[i].id) {
          this.deleteAssessmentList.push(item)
          this.assessmentList.splice(i, 1)
          console.log(this.assessmentList)
          console.log(this.deleteAssessmentList)
        }
      }
    },
    deleteFamily (item) {
      console.log('进来了')
      for (let i = 0; i < this.familyList.length; i++) {
        if (item.id === this.familyList[i].id) {
          this.deleteFamilyList.push(item)
          this.familyList.splice(i, 1)
        }
      }
    },
    changeTysb () {
      this.formItem.tysbdx = '否'
    },
    changeJs () {
      this.formItem.zsdx = '否'
    },
    changeFp () {
      this.formItem.fpyy = ''
    },
    saveInfo () {
      console.log('这是保存的按钮')
      if (!this.formItem.card_no) {
        this.$Message.error('请先填写证件号码！')
        return
      }
      let params = {}
      if (this.formItem.bysj) {
        params.bysj = date2str(this.formItem.bysj)
      }
      if (this.formItem.rzsj) {
        params.rzsj = date2str(this.formItem.rzsj)
      }
      if (this.formItem.rz_time) {
        params.rz_time = date2str(this.formItem.rz_time)
      }
      if (this.formItem.shgzssj) {
        params.shgzssj = date2str(this.formItem.shgzssj)
      }
      if (this.formItem.lxjn_time) {
        params.lxjn_time = date2str(this.formItem.lxjn_time)
      }
      if (this.formItem.qksg_time) {
        params.qksg_time = date2str(this.formItem.qksg_time)
      }
      if (this.formItem.cjjn_time) {
        params.cjjn_time = date2str(this.formItem.cjjn_time)
      }
      if (this.formItem.lxjn_time) {
        params.lxjn_time = date2str(this.formItem.lxjn_time)
      }
      if (this.formItem.id) {
        params.id = this.formItem.id
      }
      params = {
        ...params,
        id: this.formItem.id,
        type: this.formItem.type,
        name: this.formItem.name,
        card_no: this.formItem.card_no,
        phone: this.formItem.phone,
        sex: this.formItem.sex,
        hunyin: this.formItem.hunyin,
        minzu: this.formItem.minzu,
        zzmm: this.formItem.zzmm,
        dwzw: this.formItem.dwzw,
        jwzw: this.formItem.jwzw,
        jwcy: this.formItem.jwcy,
        hj_address: this.formItem.hj_address,
        jt_address: this.formItem.jt_address,
        mgzp: this.formItem.mgzp,
        sfzzm: this.formItem.sfzzm,
        sfzfm: this.formItem.sfzfm,

      }
      if (this.formItem.type === '1') {
        params = {
          ...params,
          tysb: this.formItem.tysb,
          tysbdx: this.formItem.tysbdx,
          js: this.formItem.js,
          zsdx: this.formItem.zsdx,
          xhzw: this.formItem.xhzw,
          dbhzn: this.formItem.dbhzn,
          byyx: this.formItem.byyx,
          sxzy: this.formItem.sxzy,
          zgxl: this.formItem.zgxl,
          xw: this.formItem.xw,
          bscj: this.formItem.bscj,
          mscj: this.formItem.mscj,
          qksgzg: this.formItem.qksgzg,
          shgzs: this.formItem.shgzs,
          fp: this.formItem.fp,
          fpyy: this.formItem.fpyy,
          pxjl: this.formItem.pxjl,
          pxpd: this.formItem.pxpd,
          ldht: this.formItem.ldht,
          ldhtjf: this.formItem.ldhtjf,
          qtjf: this.formItem.qtjf,
          ldgxzm: this.formItem.ldgxzm,
          qtzm: this.formItem.qtzm,
          czfdbx: this.formItem.czfdbx,
          qtczfdbx: this.formItem.qtczfdbx,
          lxjn: this.formItem.lxjn,
          familyList: this.familyList,
          assessmentList: this.assessmentList,
          deleteAssessmentList: this.deleteAssessmentList,
          deleteFamilyList: this.deleteFamilyList
        }
      } else if (this.formItem.type === '2') {
        params = {
          ...params,
          byyx: this.formItem.byyx,
          sxzy: this.formItem.sxzy,
          zgxl: this.formItem.zgxl,
          xw: this.formItem.xw,
        }
      }
      saveInfo(params).then(res => {
        if (res.data.errcode === 0) {
          this.$Message.success('操作成功')
          this.$router.push({
            path: '/personnel-list',
            query: { labelList: this.labelList }
          })
        } else {
          this.$Message.error(res.data.errmsg);
        }
      })
    },
    changeCard (no) {
      let id = no
      let flag = true
      //转换大小写
      id = id.toUpperCase()
      let arrVerifyCode = [1, 0, "X", 9, 8, 7, 6, 5, 4, 3, 2]
      let Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
      // let Checker = [1, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1]
      if (id.length != 15 && id.length != 18) {
        flag = false
      }
      let Ai = id.length == 18 ? id.substring(0, 17) : id.slice(0, 6) + "19" + id.slice(6, 16)
      if (!/^\d+$/.test(Ai)) {
        flag = false
      }
      let yyyy = Ai.slice(6, 10),
        mm = Ai.slice(10, 12) - 1,
        dd = Ai.slice(12, 14)
      let d = new Date(yyyy, mm, dd),
        now = new Date()
      let year = d.getFullYear(),
        mon = d.getMonth(),
        day = d.getDate()
      if (year != yyyy || mon != mm || day != dd || d > now || year < 1800) {
        flag = false
      }
      let ret = 0
      for (let i = 0; i < 17; i++) {
        ret += Ai.charAt(i) * Wi[i]
      }
      Ai += arrVerifyCode[(ret %= 11)]
      if (id.length == 18 && id != Ai) {
        flag = false
      }
      console.log(flag)
      if (flag) {
        let num = no.charAt(16);
        if(num%2==0){
          this.formItem.sex = '女'
        }else{
          this.formItem.sex = '男'
          console.log('男')
        }
      } else {
        this.formItem.sex = ''
      }
    }
  },
  mounted() {
    this.getPersonTypeInfo()
    if (this.$route.query.labelList) {
      this.labelList = this.$route.query.labelList
    } else {
      this.getLabelList()
    }
    this.getCity(2, null, 'areaList', false)
    if (this.$route.query.id) {
      this.getPersonnelInfo()
    } else {
      if (this.level === '40') {
        this.formItem = {
          type: '1',
          mgzp: '',
          sfzzm: '',
          sfzfm: '',
          area1: '',
          state: ''
        }
      } else {
        this.formItem = {
          type: '2',
          mgzp: '',
          sfzzm: '',
          sfzfm: '',
          area1: '',
          state: ''
        }
      }
    }
    if (this.$route.query.disabledInfo) {
      this.disabledInfo = this.$route.query.disabledInfo
    } else {
      this.disabledInfo = false
    }
    console.log(this.formItem)
  },
  computed: {
    companyGrade () {
      return this.$store.state.user.severUserInfo.company_grade
    },
    companyCode () {
      return this.$store.state.user.severUserInfo.company_code
    },
    level () {
      return this.$store.state.user.severUserInfo.level
    }
  }
}
</script>
<style>
.title-style {
  padding: 8px 12px;
  background-color: #ecf8ff;
  border-radius: 4px;
  border-left: 5px solid #50bfff;
  margin: 15px 0;
  font-size: 16px;
  width: 100%;
}
.ivu-input[disabled], fieldset[disabled] .ivu-input {
  background-color: #f3f3f3;
  opacity: 1;
  cursor: not-allowed;
  color: #000000;
}
.ivu-select-disabled .ivu-select-selection {
  background-color: #f3f3f3;
  opacity: 1;
  cursor: not-allowed;
  color: #000000;
}
.ivu-select-input[disabled] {
  cursor: not-allowed;
  color: #000000;
  -webkit-text-fill-color: #000000;
}
</style>
